import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Take extends JPanel implements ActionListener {//取钱
    private JButton backBtn;
    private Start frame;
    private JTextField quq=new JTextField();
    private JButton backBtn1;
    private Icon anj1=Util.getIcon("/images/buttonSure.jpg");
    private Icon anj=Util.getIcon("/images/buttonOff.jpg");

    public JTextField getQuq() {
        return quq;
    }

    public void setQuq(JTextField quq) {
        this.quq = quq;
    }

    public Take(Start frame) {
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);
        JLabel titleLabel = new JLabel("取钱");
        titleLabel.setBounds(380, 10, 100, 50);
        this.add(titleLabel);

        quq.setBounds(350,250,100,20);
        this.add(quq);

        backBtn = new JButton(anj);
        backBtn.setBounds(450, 350, 100, 50);
        this.add(backBtn);
        backBtn.addActionListener(this);

        backBtn1 = new JButton(anj1);
        backBtn1.setBounds(250, 350, 100, 50);
        this.add(backBtn1);
        backBtn1.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (backBtn == e.getSource()) {
            frame.switchPanel("menu");
        }else if (backBtn1==e.getSource()){
            double cci= (frame.getUser().getInformation().get(frame.getLoginPanel().getInd()).getBalance())-Double.valueOf(frame.getQue().getQuq().getText());
            frame.getUser().getInformation().get(frame.getLoginPanel().getInd()).setBalance(cci);
            frame.switchPanel("menu");
        }
    }
}
